package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.common.mapper.UserInfoMapper;
import com.tanhua.common.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    public UserInfo queryTodayBestById(Long id) {
        QueryWrapper<UserInfo>  queryWrapper= new QueryWrapper<>();
        queryWrapper.eq("user_id",id);
        UserInfo userInfo = userInfoMapper.selectOne(queryWrapper);
        return userInfo;
    }

    public List<UserInfo> queryUserInfoList(QueryWrapper<UserInfo> queryWrapper) {
        return this.userInfoMapper.selectList(queryWrapper);
    }

    public List<UserInfo> queryUserInfoByUserIdList(List<Object> userIdList){
        QueryWrapper<UserInfo>  queryWrapper= new QueryWrapper<>();
        queryWrapper.in("user_id", userIdList);
        List<UserInfo> userInfos = userInfoMapper.selectList(queryWrapper);
        return userInfos;
    }

    public UserInfo queryUserInfoByUserId(Long id) {
        QueryWrapper<UserInfo>  queryWrapper= new QueryWrapper<>();
        queryWrapper.eq("user_id", id);
        //UserInfo userInfo = userInfoMapper.selectOne(queryWrapper);
        UserInfo userInfo = userInfoMapper.selectById(id);
        return userInfo;
    }


    public boolean updateUserInfoById(UserInfo userInfo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userInfo.getUserId());
        return userInfoMapper.update(userInfo,queryWrapper)>0;
    }
}
